﻿using Microsoft.EntityFrameworkCore;
using Student.Application;
using Student.EFCore;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Autofac;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;

namespace Student.ApiHost
{
    [DependsOn(
        typeof(StudentSwaggerModule),
        typeof(AbpAspNetCoreMvcModule),
        typeof(StudentApplicationModule),
        typeof(AbpAutofacModule),
        typeof(StudentEFCoreModule)
    )]
    public class StudentApiHostModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var services = context.Services;
            Configure<AbpAspNetCoreMvcOptions>(options =>
            {
                options.ConventionalControllers.Create(typeof(StudentApplicationModule).Assembly);
            });
            Configure<AbpDbContextOptions>(options =>
            {
                options.UseSqlite();
            });

            services.AddControllers();
        }

        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = (WebApplication)context.GetApplicationBuilder();

            app.UseAuthorization();

            app.MapControllers();
        }
    }
}